function All() {}
All.prototype = {
  timer: '',
  debounce(fn, delay = 500) {
    var _this = this
    return function(arg) {
      // 获取函数的作用域和变量
      const that = this
      const args = arg
      clearTimeout(_this.timer) // 清除定时器
      _this.timer = setTimeout(function() {
        fn.call(that, args)
      }, delay)
    }
  },
  setCookie(val) { // cookie设置[{key:value}]、获取key、清除['key1','key2']
    for (var i = 0, len = val.length; i < len; i++) {
      for (var key in val[i]) {
        document.cookie = key + '=' + encodeURIComponent(val[i][key]) + '; path=/'
      }
    }
  },
  getCookie(name) {
    var strCookie = document.cookie
    var arrCookie = strCookie.split('; ')
    for (var i = 0, len = arrCookie.length; i < len; i++) {
      var arr = arrCookie[i].split('=')
      if (name === arr[0]) {
        return decodeURIComponent(arr[1])
      }
    }
  },
  clearCookie(name) {
    var myDate = new Date()
    myDate.setTime(-1000) // 设置时间
    for (var i = 0, len = name.length; i < len; i++) {
      document.cookie = '' + name[i] + "=''; path=/; expires=" + myDate.toGMTString()
    }
  },
  arrToStr(arr) {
    if (arr) {
      return arr.map(item => { return item.name }).toString()
    }
  },
  toggleClass(arr, elem, key = 'id') {
    return arr.some(item => { return item[key] === elem[key] })
  },
  setApproverStr(nodeConfig) {
    if (nodeConfig.settype === 1) {
      if (nodeConfig.nodeUserList.length === 1) {
        return nodeConfig.nodeUserList[0].name
      } else if (nodeConfig.nodeUserList.length > 1) {
        if (nodeConfig.examineMode === 1) {
          return this.arrToStr(nodeConfig.nodeUserList)
        } else if (nodeConfig.examineMode === 2) {
          return nodeConfig.nodeUserList.length + '人会签'
        }
      }
    } else if (nodeConfig.settype === 2) {
      const level = nodeConfig.directorLevel === 1 ? '直接主管' : '第' + nodeConfig.directorLevel + '级主管'
      if (nodeConfig.examineMode === 1) {
        return level
      } else if (nodeConfig.examineMode === 2) {
        return level + '会签'
      }
    } else if (nodeConfig.settype === 4) {
      if (nodeConfig.selectRange === 1) {
        return '发起人自选'
      } else {
        if (nodeConfig.nodeUserList.length > 0) {
          if (nodeConfig.selectRange === 2) {
            return '发起人自选'
          } else {
            return '发起人从' + nodeConfig.nodeUserList[0].name + '中自选'
          }
        } else {
          return ''
        }
      }
    } else if (nodeConfig.settype === 5) {
      return '发起人自己'
    } else if (nodeConfig.settype === 7) {
      return '从直接主管到通讯录中级别最高的第' + nodeConfig.examineEndDirectorLevel + '个层级主管'
    }
  },
  dealStr(str, obj) {
    const arr = []
    const list = str.split(',')
    for (var elem in obj) {
      list.map(item => {
        if (item === elem) {
          arr.push(obj[elem].value)
        }
      })
    }
    return arr.join('或')
  },
  conditionStr(nodeConfig, index) {
    var { conditionList, nodeUserList } = nodeConfig.conditionNodes[index]
    if (conditionList.length === 0) {
      return (index === nodeConfig.conditionNodes.length - 1) && nodeConfig.conditionNodes[0].conditionList.length !== 0 ? '其他条件进入此流程' : '请设置条件'
    } else {
      let str = ''
      if (nodeUserList.length !== 0) {
        str += '发起人：'
        str += nodeUserList.map(item => { return item.name }).join('或') + ' 并且 '
      }
      for (var i = 0; i < conditionList.length; i++) {
        var { type, label, value, optType, optionItems } = conditionList[i]

        if (label && value && (type === 'input' || type === 'textarea')) {
          str += label + '包含：' + value + ' 并且 '
        }
        if (label && type === 'number' && optType) {
          str += label + optType + value + ' 并且 '
        }
        if (label && value && type === 'radio' && optionItems) {
          const v = optionItems.find(m => m.value === value) || {}
          str += label + '=' + v.label + ' 并且 '
        }
        if (label && value && type === 'select' && optionItems) {
          const v = optionItems.find(m => m.value === value) || {}
          str += label + '=' + v.label + ' 并且 '
        }
        if (label && value && type === 'checkbox' && optionItems) {
          const v = optionItems.filter(m => value.includes(m.value)).map(p => p.label)
          str += label + '=' + v.join(',') + ' 并且 '
        }
      }
      return str ? str.substring(0, str.length - 4) : '请设置条件'
    }
  },
  copyerStr(nodeConfig) {
    if (nodeConfig.nodeUserList.length !== 0) {
      return this.arrToStr(nodeConfig.nodeUserList)
    } else {
      if (nodeConfig.ccSelfSelectFlag === 1) {
        return '发起人自选'
      }
    }
  }
}

export default new All()
